<?php
	class ArchivePressLog {
		
		const LOG_ON		= "on";
		const LOG_OFF		= "off";
		
		const LOG_BASIC		= "basic";
		const LOG_DEBUG		= "debug";
		
		private $wpdb;							// global wp db class
		private $logTable;						// the log database table
		private $logStatus	= self::LOG_ON;		// log status: yes>log, no>don't log
		private $logLevel	= self::LOG_BASIC;	// type of log
		
		function __construct($logTable,$logStatus=self::ON,$logLevel=self::LOG_BASIC){
			// init table (its name can be different from the standard one )
			$this->logTable		= $logTable;
			// Other inits
			$this->logStatus	= $logStatus;
			$this->logLevel		= $logLevel;
			
			// set global db connection (and class)
			global $wpdb;
			$this->wpdb = $wpdb;
		}
		
		// log into the database
		public function logIt($level,$message) {
			// only if the logging is enabled
			if($this->logStatus == self::LOG_ON){
				// only if the level is the one decided
				if(($level == self::LOG_BASIC) || ($this->logLevel == self::LOG_DEBUG) ) {
					$this->wpdb->query("INSERT INTO ".$this->logTable." 
					(id,log_date,level,message) 
					VALUES ('',FROM_UNIXTIME(".strtotime(date('Y-m-d H:i:s'))."),'".$this->wpdb->escape($level)."','".$this->wpdb->escape($message)."') ");
				}
			}
		}
		// start the log system
		public function startLogging() {
			$this->logStatus = self::LOG_ON;
		}
		
		// stop logging
		public function stopLogging() {
			$this->logStatus = self::LOG_OFF;
		}
		
		// change the log level
		public function basic() {
			$this->logLevel = self::LOG_BASIC;
		}
		public function debug() {
			$this->logLevel = self::LOG_DEBUG;
		}
		
	}

?>